package com.zeng.jiudian.servlet.hotel;

import com.alibaba.fastjson.JSONObject;
import com.zeng.jiudian.service.HotelService;
import com.zeng.jiudian.service.impl.HotelServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JJ_yo
 * @Date 2020/7/28 - 14:04
 */
@WebServlet("/back/hotel/del")
public class HotelDelServlet extends HttpServlet
{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");

        String idString = req.getParameter("id");
        int id = (idString == null || "".equals(idString) ? 0 : Integer.parseInt(idString));

        HotelService hotelService = new HotelServiceImpl();
        int result = hotelService.delById(id);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        resp.getWriter().println(jsonObject);
    }
}
